package edu.zut.cs.software.practice;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 
 * @author 陈明阳
<<<<<<< HEAD
 * @author 马江涛
=======
 * @author 黄靖
>>>>>>> 05ca3405ac39cef5e837c5927862f04da93739e0
 *
 */
public class JDBC {
	private static String url,user,pwd;
	
	static {	
		url="jdbc:mysql://localhost:3306/student_info";
		user="student";
		pwd="st_123456";		
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static Connection getConn() {		
		Connection conn=null;
		
		try {
			conn = DriverManager.getConnection(url,user,pwd);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return conn;		
	}
	
	public static void free(ResultSet rs,PreparedStatement ps,Connection conn) {
		
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(ps!=null) {
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		if(conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
	}
}
